function convert (value) {
  return value.replace(/<[^<>]+>/ig, '').replace(/$nbsp;/ig, '').replace(/&ensp;/ig, '').replace(/&gt;/ig, '')
}
import { BASEURL } from '@/api/config'
export const crudOptions = vm => {
  return {
    indexRow: {
      title: '序号',
      align: 'center'
    },
    options: {
      height: '100%' // 表格高度100%, 使用toolbar必须设置
    },
    columns: [
      {
        title: '公告标题',
        key: 'title',
        align: 'center',
        search: {
          disabled: false
        }
      },
      {
        title: '发布人',
        key: 'announcer',
        align: 'center'
      },
      {
        title: '公告内容',
        key: 'content',
        align: 'center',
        width: 300,
        type: 'editor-quill',
        disabled: false,
        form: {
          component: {
            props: {
              uploader: {
                type: 'form', //临时修改上传后端为form方式
                action: `${BASEURL}/api/file/upload`, // 临时修改form表单上传url
                name: 'file',
                headers: {},
                data: {},
                successHandle (ret) {
                  // console.log(ret)
                  return { url: ret.data.url }
                }
              }
            }
          },
          events: {
            'text-change': event => {
              console.log(event)
            }
          },
          show (context) {
            return context.form.change === 'quill'
          }
        },
        formatter (row) {
          return convert(row.content).length > 10 ? convert(row.content).substring(0, 10) + '...' : convert(row.content)
        }
      },
      {
        title: '发布时间',
        key: 'createdAt',
        align: 'center',
        form: { disabled: true }
      }
    ],
    rowHandle: {
      align: 'center',
      view: false
    }
  }
}
